#_*_encoding :utf-8_*_
import threading
from com.zjs.crawer.urlhook.lianjia import LianJiaHook
from com.zjs.crawer.urlpath.lianjia import LianJiaPath
from com.zjs.crawer.urlcontent.lianjia import LianJiaContent

from com.zjs.crawer.urlhook.zhilian import ZhiLianHook
from com.zjs.crawer.urlpath.zhilian import ZhiLianPath
from com.zjs.crawer.urlcontent.zhilian import ZhiLianContent

from com.zjs.crawer.urlhook.taobaoHook import taobaoHooks
from com.zjs.crawer.urlpath.taobaoPath import taobaoPaths
from com.zjs.crawer.urlcontent.taobao import TaoBaoContent

from com.zjs.crawer.urlhook.jobHook import jobHooks
from com.zjs.crawer.urlpath.jobPath import jobPaths
from com.zjs.crawer.urlcontent.jobContent import jobContents

import logging

from com.zjs.crawer.urlhook.baseurlhook import BaseUrlHook


class CrawerMain(object):
    
    def run(self):
        logging.debug("start!")
#         self.runlianjia()
#         self.runqcwy()
#         threads = []
#         threadBnum = 8
#         threadCnum = 4
#         t = threading.Thread(target=BaseUrlHook().run)
#         threads.append(t)
#         for t in threads:
#             t.start()
#         self.runzhilian()
        self.taobao()
        
    def runzhilian(self):
        logging.debug("开始爬取智联！")
        threads = []
        homeurl = "http://sou.zhaopin.com/jobs/searchresult.ashx?jl=%E6%B7%B1%E5%9C%B3&kw=%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90&isadv=0&sg=5a0d8b7ea80d4083b3f78787eee559b2&p=1"
        threadAnum = 4
        threadBnum = 8
        threadCnum = 4
        for i in range(0,threadAnum):
            t = threading.Thread(target=ZhiLianHook(homeurl).run)
            threads.append(t)
            
        for i in range(0,threadBnum):
            t = threading.Thread(target=ZhiLianPath().run)
            threads.append(t)
            
        for i in range(0,threadCnum):
            t = threading.Thread(target=ZhiLianContent().run)
            threads.append(t)
            
        for t in threads:
            t.start()
            
        
        
        
    def runlianjia(self):
        logging.debug("开始爬取链家！")
        threads = []
        homeurl = "http://fs.lianjia.com/zufang/"
        threadAnum = 1
        threadBnum = 2
        threadCnum = 1
        for i in range(0,threadAnum):
            t = threading.Thread(target=LianJiaHook(homeurl).run)
            threads.append(t)
            
        for i in range(0,threadBnum):
            t = threading.Thread(target=LianJiaPath().run)
            threads.append(t)
            
        for i in range(0,threadCnum):
            t = threading.Thread(target=LianJiaContent().run)
            threads.append(t)
            
        for t in threads:
            t.start()
        
        
    
    def runqcwy(self):
        logging.debug("开始爬取前程无忧！")
        threads = []
        homeurl = "http://search.51job.com/list/040000,000000,0000,00,9,99,%2520,2,1.html?lang=c&stype=&postchannel=0000&workyear=99&cotype=99&degreefrom=99&jobterm=99&companysize=99&providesalary=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&line=&specialarea=00&from=&welfare="
        threadAnum = 4
        threadBnum = 8
        threadCnum = 4
        for i in range(0,threadAnum):
            t = threading.Thread(target=jobHooks(homeurl).run)
            threads.append(t)
            
        for i in range(0,threadBnum):
            t = threading.Thread(target=jobPaths().run)
            threads.append(t)
            
        for i in range(0,threadCnum):
            t = threading.Thread(target=jobContents().run)
            threads.append(t)
            
        for t in threads:
            t.start()
            
    
    def taobao(self):
        logging.debug("开始爬取淘宝！")
        threads = []
        homeurl = "https://shopsearch.taobao.com/search?app=shopsearch&q=%E6%95%B0%E7%A0%81&imgfile=&js=1&stats_click=search_radio_all%3A1&initiative_id=staobaoz_20170609&ie=utf8"
        threadAnum = 1
        threadBnum = 2
        threadCnum = 1
        for i in range(0,threadAnum):
            t = threading.Thread(target=taobaoHooks(homeurl).run)
            threads.append(t)
            
        for i in range(0,threadBnum):
            t = threading.Thread(target=taobaoPaths().run)
            threads.append(t)
            
        for i in range(0,threadCnum):
            t = threading.Thread(target=TaoBaoContent().run)
            threads.append(t)
            
        for t in threads:
            t.start()
            